<?php
namespace app\admin\controller;

use think\facade\View;
class Image extends AdminBase
{
	public function upload(){
		if(!$this->request->isPost()){
			return show(config('status.error'),'请求不合法');
		}
		$file = $this->request->file("file");
		//$filename = \think\facade\Filesystem::putFile('upload',$file);
		$filename = \think\facade\Filesystem::disk('public')->putFile('image',$file);
		//echo $filename;
		if(!$filename){
			return show(config('status.error'),'上传图片失败');
		}
		$imgUrl = [
			'image' => "/upload/".$filename,
		];
		return show(config('status.success'),'上传图片成功',$imgUrl);
	}

	// 文本编辑器图片上传
	public function layUpload(){
		if(!$this->request->isPost()){
			return show(config('status.error'),'请求不合法');
		}
		$file = $this->request->file("file");
		$filename = \think\facade\Filesystem::disk('public')->putFile('image',$file);
		if(!$filename){
			return json(['code'=>1,'data'=>[]],200);
		}
		$result = [
			'code'=>0,
			'data'=>[
				'src'=>"/upload/".$filename,
			],
		];
		return json($result,200);
	}
}